package src.Skills;

import src.Main;
import src.Players.*;
import src.Packets.*;
import src.Util.Timer;

public class Fishing {
	private int fishXPRate = 1;
	private Player p;
	private PlayerItems pi;
	private int[] shrimpItems = {317};
	private int[] sardineItems = {327};
	private int[] herringItems = {345};
	private int[] mackerelItems = {353, 353, 353, 353, 353,
									353, 353, 353, 353, 353,
									405, 401, 401, 407
		};
	private int[] troutItems = {335};
	private int[] codItems = {341, 341, 341, 341, 341,
								341, 341, 341, 341, 341,
								405, 401, 401, 407
		};
	private int[] pikeItems = {349};
	private int[] salmonItems = {331};
	private int[] tunaItems = {359};
	private int[] lobsterItems = {377};
	private int[] bassItems = {363, 363, 363, 363, 363,
								363, 363, 363, 363, 363,
								405, 401, 401, 407
		};
	private int[] sfItems = {371};
	private int[] sharkItems = {383};
	
	public Fishing(Player _p) {
		p = _p;
	}
	
	public void catchFish(int clickId) {
        if(p == null || clickId < 0)
        {
            return;
        }
        if(p.canWalkDelay > 0)
        {
            return;
        }
        int slot = 0;
	int fishLvl = p.skillLvl[10];
	PlayerItems pi = new PlayerItems();
	PlayerChecks pc = new PlayerChecks(p);
	switch(p.clickId) {
		case 13135: // shrimp
			if(!pc.playerHasItem(p, 303)) {
				p.frame.sendMessage(p, "You need a net to do that!");
				break;
			} else {
				if(fishLvl < 1) {
					p.frame.sendMessage(p, "You need at least 1 fishing to fish here.");
					break;
				} else {
						if(random(8) != 1) {
							p.frame.sendMessage(p, "You manage to catch something!");
							pi.addItem(p, shrimpItems[slot], 1);
							p.requestAnim(1461, 0);
							p.addSkillXP(10 * fishXPRate, 8);
						} else {
							break;
						}
				}
			}
			break;
			
			case 1134456: // sardine
				if(!pc.playerHasItem(p, 307) && (!pc.playerHasItem(p, 313))) {
					p.frame.sendMessage(p, "You need a fishing rod and bait to do that!");
					break;
				} else {
					if(fishLvl < 5) {
						p.frame.sendMessage(p, "You need at least 5 fishing to fish here.");
						break;
					} else {
						for(;;) {
							if(random(8) != 1) {
								p.frame.sendMessage(p, "You manage to catch something!");
								pi.addItem(p, sardineItems[slot], 1);
								pi.deleteItem(p, 313, pi.findInvSlot(p), 1);
								p.requestAnim(622, 0);
								p.addSkillXP(20 * fishXPRate, 8);
							} else {
								break;
							}
						}
					}
				}
			break;
			
			case 2353535: // herring
				if(!pc.playerHasItem(p, 307) && (!pc.playerHasItem(p, 313))) {
					p.frame.sendMessage(p, "You need a fishing rod and bait to do that!");
					break;
				} else {
					if(fishLvl < 10) {
						p.frame.sendMessage(p, "You need at least 10 fishing to fish here.");
						break;
					} else {
						for(;;) {
							if(random(8) != 1) {
								p.frame.sendMessage(p, "You manage to catch something!");
								pi.addItem(p, herringItems[slot], 1);
								pi.deleteItem(p, 313, pi.findInvSlot(p), 1);
								p.requestAnim(622, 0);
								p.addSkillXP(30 * fishXPRate, 8);
							} else {
								break;
							}
						}
					}
				}
			break;
			
			case 1254646: // mackerel - premium
				if(!pc.playerHasItem(p, 305)) {
					p.frame.sendMessage(p, "You need a big net to do that!");
					break;
				} else {
					if(fishLvl < 16) {
						p.frame.sendMessage(p, "You need at least 16 fishing to fish here.");
						break;
					} else {
						for(;;) {
							if(random(8) != 1) {
								p.frame.sendMessage(p, "You manage to catch something!");
								pi.addItem(p, mackerelItems[slot], 1);
								p.requestAnim(1461, 0);
								p.addSkillXP(20 * fishXPRate, 8);
							} else {
								break;
							}
						}
					}
				}
			break;
			
			case 11245: // trout
				if(!pc.playerHasItem(p, 309) && (!pc.playerHasItem(p, 314))) {
					p.frame.sendMessage(p, "You need a fly fishing rod and feathers to do that!");
					break;
				} else {
					if(fishLvl < 20) {
						p.frame.sendMessage(p, "You need at least 20 fishing to fish here.");
						break;
					} else {
						for(;;) {
							if(random(8) != 1) {
								p.frame.sendMessage(p, "You manage to catch something!");
								pi.addItem(p, troutItems[slot], 1);
								pi.deleteItem(p, 314, pi.findInvSlot(p), 1);
								p.requestAnim(622, 0);
								p.addSkillXP(50 * fishXPRate, 8);
							} else {
								break;
							}
						}
					}
				}
			break;
			
			case 780465: // cod - premium
				if(!pc.playerHasItem(p, 305)) {
					p.frame.sendMessage(p, "You need a big net to do that!");
					break;
				} else {
					if(fishLvl < 23) {
						p.frame.sendMessage(p, "You need at least 23 fishing to fish here.");
						break;
					} else {
						for(;;) {
							if(random(8) != 1) {
								p.frame.sendMessage(p, "You manage to catch something!");
								pi.addItem(p, codItems[slot], 1);
								p.requestAnim(1461, 0);
								p.addSkillXP(45 * fishXPRate, 8);
							} else {
								break;
							}
						}
					}
				}
			break;
			
			case 13235: // pike
				if(!pc.playerHasItem(p, 307) && (!pc.playerHasItem(p, 313))) {
					p.frame.sendMessage(p, "You need a fishing rod and bait to do that!");
					break;
				} else {
					if(fishLvl < 25) {
						p.frame.sendMessage(p, "You need at least 25 fishing to fish here.");
						break;
					} else {
						for(;;) {
							if(random(8) != 1) {
								p.frame.sendMessage(p, "You manage to catch something!");
								pi.addItem(p, pikeItems[slot], 1);
								pi.deleteItem(p, 313, pi.findInvSlot(p), 1);
								p.requestAnim(622, 0);
								p.addSkillXP(60 * fishXPRate, 8);
							} else {
								break;
							}
						}
					}
				}
			break;
			
			case 23636: //salmon
				if(!pc.playerHasItem(p, 309) && (!pc.playerHasItem(p, 314))) {
					p.frame.sendMessage(p, "You need a fly fishing rod and feathers to do that!");
					break;
				} else {
					if(fishLvl < 30) {
						p.frame.sendMessage(p, "You need at least 30 fishing to fish here.");
						break;
					} else {
						for(;;) {
							if(random(8) != 1) {
								p.frame.sendMessage(p, "You manage to catch something!");
								pi.addItem(p, salmonItems[slot], 1);
								pi.deleteItem(p, 314, pi.findInvSlot(p), 1);
								p.requestAnim(622, 0);
								p.addSkillXP(70 * fishXPRate, 8);
							} else {
								break;
							}
						}
					}
				}
			break;
			
			case 924786: // tuna
				if(!pc.playerHasItem(p, 311)) {
					p.frame.sendMessage(p, "You need a harpoon to do that!");
					break;
				} else {
					if(fishLvl < 35) {
						p.frame.sendMessage(p, "You need at least 35 fishing to fish here.");
						break;
					} else {
						for(;;) {
							if(random(8) != 1) {
								p.frame.sendMessage(p, "You manage to catch something!");
								pi.addItem(p, tunaItems[slot], 1);
								p.requestAnim(618, 0);
								p.addSkillXP(80 * fishXPRate, 8);
							} else {
								break;
							}
						}
					}
				}
			break;
			
			case 124566: // lobster
				if(!pc.playerHasItem(p, 301)) {
					p.frame.sendMessage(p, "You need a cage to do that!");
					break;
				} else {
					if(fishLvl < 40) {
						p.frame.sendMessage(p, "You need at least 40 fishing to fish here.");
						break;
					} else {
						for(;;) {
							if(random(8) != 1) {
								p.frame.sendMessage(p, "You manage to catch something!");
								pi.addItem(p, lobsterItems[slot], 1);
								p.requestAnim(619, 0);
								p.addSkillXP(90 * fishXPRate, 8);
							} else {
								break;
							}
						}
					}
				}
			break;
			
			case 15686: // bass - premium
				if(!pc.playerHasItem(p, 305)) {
					p.frame.sendMessage(p, "You need a big net to do that!");
					break;
				} else {
					if(fishLvl < 46) {
						p.frame.sendMessage(p, "You need at least 46 fishing to fish here.");
						break;
					} else {
						for(;;) {
							if(random(8) != 1) {
								p.frame.sendMessage(p, "You manage to catch something!");
								pi.addItem(p, bassItems[slot], 1);
								p.requestAnim(1461, 0);
								p.addSkillXP(100 * fishXPRate, 8);
							} else {
								break;
							}
						}
					}
				}
			break;
			
			case 13512: // swordfish
				if(!pc.playerHasItem(p, 311)) {
					p.frame.sendMessage(p, "You need a harpoon to do that!");
					break;
				} else {
					if(fishLvl < 50) {
						p.frame.sendMessage(p, "You need at least 50 fishing to fish here.");
						break;
					} else {
						for(;;) {
							if(random(8) != 1) {
								p.frame.sendMessage(p, "You manage to catch something!");
								pi.addItem(p, sfItems[slot], 1);
								p.requestAnim(618, 0);
								p.addSkillXP(100 * fishXPRate, 8);
							} else {
								break;
							}
						}
					}
				}
			break;
			
			case 28563: // shark - premium
				if(!pc.playerHasItem(p, 311)) {
					p.frame.sendMessage(p, "You need a harpoon to do that!");
					break;
				} else {
					if(fishLvl < 76) {
						p.frame.sendMessage(p, "You need at least 76 fishing to fish here.");
						break;
					} else {
						for(;;) {
							if(random(8) != 1) {
								p.frame.sendMessage(p, "You manage to catch something!");
								pi.addItem(p, sharkItems[slot], 1);
								p.requestAnim(618, 0);
								p.addSkillXP(110 * fishXPRate, 8);
							} else {
								break;
							}
						}
					}
				}
			break;
			
			default:
				Main.m.log("[" + p.playerIndex + "-" + p.username + "] Unable to fish");
			break;
		}
	}
	
    private int random(int range)
    {
        return (int)(Math.random() * range);
    }
}